Carbon


PackBits

Header: Quickdraw.h Carbon status: Supported

Compresses a data buffer stored in RAM.

void PackBits (
    Ptr *srcPtr, 
    Ptr *dstPtr, 
    SInt16 srcBytes
);
Parameter descriptions
srcPtr

On entry, a pointer to the first byte of a buffer of data to be compressed. On exit, a pointer to the first byte following the bytes compressed.

dstPtr

On entry, a pointer to the first byte in which to store compressed data. On exit, a pointer to the first byte following the compressed data.

srcBytes

The number of bytes of uncompressed data to be compressed. In versions of software prior to version 6.0.2, this number must be 127 or less.

DISCUSSION

You must allocate memory for the destination buffer itself. Allocate enough memory for a worst-case scenario where the destination buffer is 128 bytes long for each block of source data up to 127 bytes. Use the following formula to determine how much space to allocate for the destination buffer:

maxDstBytes := srcBytes + (srcBytes+126) DIV 127;

where maxDstBytes stands for the maximum number of destination bytes.

The PackBits algorithm is most effective on data buffers in which there are likely to be series of bytes containing the same value. For example, resources of many formats often contain many consecutive zeros. If you have a data buffer in which there are only likely to be a series of words or long words containing the same values, PackBits is unlikely to be effective.

SPECIAL CONSIDERATIONS

Because your application must allocate memory for the source and destination buffers, PackBits does not move relocatable blocks. Thus, you can call it at interrupt time.

Because PackBits changes the values of the srcPtr and dstPtr parameters, you should pass to PackBits only copies of the pointers to the source and destination buffers. This allows you to access the beginning of the source and destination buffers after PackBits returns. Also, if the source or destination buffer is stored in an unlocked, relocatable block, this technique prevents PackBits from changing the value of a master pointer, which would make the original handle invalid.

AVAILABILITY

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)